<?php

namespace App\Http\Repository;

use App\Repository\BaseRepository;
use Illuminate\Database\Eloquent\Model;

class ActivityRepository extends BaseRepository
{

    function model()
    {
        return "App\\Http\\Model\\Activity";
    }

    public function transform(Model $model)
    {
        $currentAt = time();
        $model->current_at = $currentAt;
        if ($currentAt < $model->start_at) {
            $model->status = 1;
        } else if ($currentAt >= $model->start_at && $currentAt <= $model->end_at) {
            $model->status = 2;
        } else {
            $model->status = 3;
        }

        $model->user_status = 1; // 未参与抢购
        if ($model->log != null)
            $model->user_status = ($model->log->is_success == 1) ? 2 : 3; //2 参与抢购，成功 3参与抢购，未成功
        unset($model->log);

        $model->is_shared = 0; // 未分享
        if ($model->share_log != null)
            $model->is_shared = 1; // 已分享
        unset($model->share_log);
    }

}

//use Prettus\Repository\Eloquent\BaseRepository;
//use Prettus\Repository\Traits\CacheableRepository;
//
//class ActivityRepository extends BaseRepository
//{
//    protected $cacheMinutes = 10;
//
//    protected $cacheOnly = ['all' => 5, 'list' => 1];
//
//    protected $cacheExcept = ['find'];
//
//    use CacheableRepository;
//
//    function model()
//    {
//        return "App\\Http\\Model\\Activity";
//    }
//
//    public function presenter()
//    {
//        return "App\\Http\\Presenter\\ActivityPresenter";
//    }
//}
